package com.guigu.qingcheng.mapper;

import com.guigu.qingcheng.pojo.TbBrand;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

public interface TbBrandMapper extends Mapper<TbBrand> {

    @Select("SELECT * FROM tb_brand tb INNER JOIN tb_category_brand tcb ON tb.id = tcb.brand_id\n" +
            " INNER JOIN tb_category tc ON tc.id = tcb.category_id where tc.id = #{categoryId}")
    List<TbBrand> queryTbBrandByCategoryId(Integer categoryId);

    // 根据分类名称查询品牌名称和图片
    @Select("SELECT name,image FROM tb_brand WHERE id IN (SELECT brand_id FROM tb_category_brand WHERE category_id IN\n" +
            "(SELECT id FROM tb_category WHERE NAME = #{name})\n" +
            ") order by seq")
    List<Map> findByCategoryName(@Param("name") String name);
}